//
//  Contacts.m
//  17-SandBoxHomeWork
//
//  Created by 曹曹 on 16/8/5.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "Contacts.h"

@implementation Contacts
/**
 使用tableView完成通讯录, 注意联系人使用类创建
 添加联系人 联系人包含 头像 姓名 联系方式 家庭住址
 联系人列表 (注意: 添加完联系人, 列表要刷新)
 删除联系人
 查看联系人详情
 */
- (instancetype)initWithName:(NSString *)name phone:(NSString *)phone address:(NSString *)address avatar:(NSString *)avatar {
    self = [super init];
    if (self) {
        _contactName = name;
        _contactPhone = phone;
        _contactAvatar = avatar;
        _contactAddress = address;
    }
    return self;
}

+ (instancetype)contactWithName:(NSString *)name phone:(NSString *)phone address:(NSString *)address avatar:(NSString *)avatar {
    return [[Contacts alloc] initWithName:name phone:phone address:address avatar:avatar];
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super init];
    if (self) {
        _contactName = [aDecoder decodeObjectForKey:@"contactName"];
        _contactPhone = [aDecoder decodeObjectForKey:@"contactPhone"];
        _contactAddress = [aDecoder decodeObjectForKey:@"contactAddress"];
        _contactAvatar = [aDecoder decodeObjectForKey:@"contactAvatar"];
    }
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder {
    [aCoder encodeObject:_contactName forKey:@"contactName"];
    [aCoder encodeObject:_contactPhone forKey:@"contactPhone"];
    [aCoder encodeObject:_contactAddress forKey:@"contactAddress"];
    [aCoder encodeObject:_contactAvatar forKey:@"contactAvatar"];
}

@end
